import React from "react";
import { createBrowserRouter } from 'react-router-dom'

import MainLayout from "../layouts/MainLayout";
import ManageLayout from "../layouts/ManageLayout";
import QuestionLayout from "../layouts/QuestionLayout";
import Home from "../pages/Home";
import Login from "../pages/Login";
import Register from "../pages/Register";
import NotFound from "../pages/NotFound";
import Trash from "../pages/manage/Trash";
import List from "../pages/manage/List";
import Star from "../pages/manage/Star";
import Edit from '../pages/question/Edit'
import Stat from '../pages/question/Stat'

const router = createBrowserRouter([
    {
        path: '/',
        element: <MainLayout />,
        children: [
            // 字路由中展示的子组件，要用在父组件的 <Outlet> 插槽中
            {
                path: '/',
                element: <Home />
            },
            {
                path: '/login',
                element: <Login />
            },
            {
                path: '/register',
                element: <Register />
            },
            {
                path: 'manage',
                element: <ManageLayout />,
                children: [
                    {
                        path: "list",
                        element: <List />
                    },
                    {
                        path: "star",
                        element: <Star />
                    },
                    {
                        path: "trash",
                        element: <Trash />
                    },
                ]
            },
            {
                path: '*',
                element: <NotFound />
            },
        ]
    }, 
    {
        path: 'question',
        element: <QuestionLayout />,
        children: [
            {
                path: 'edit/:id',
                element: <Edit />
            },
            {
                path: 'stat/:id',
                element: <Stat />
            }
        ]
    },
    // {
    //     path : "/",
    //     element:<Home/>
    // }
])

export default router

// 路由常量
export const HOME_PATHNAME = '/' // 不需要登陆
export const LOGIN_PATHNAME = '/login'
export const MANAGE_INDEX_PATHNAME = '/manage/list'
export const REGISTER_PATHNAME = '/register'

// 判断是不是登陆组册页
export function isLoginOrRegister(pathname : string){
    if([LOGIN_PATHNAME  ,REGISTER_PATHNAME ].includes(pathname)) return true
    return false
}

// 判断是不是不需要登陆的页面
export function isNoneedLog(pathname: string){
    if([HOME_PATHNAME , LOGIN_PATHNAME  ,REGISTER_PATHNAME].includes(pathname)) return true
    return false
}